import {Toast, Modal, Portal, ActionSheet } from '@ant-design/react-native';
import Toasts  from 'react-native-root-toast';
import AsyncStorage from '@react-native-community/async-storage';
import underscore from 'underscore'
const WebDomain =  'http://b2c.tixaapp.com' 
const baseURL =   WebDomain + '/clientInterface/'
// 图片地址
const getFullImage = (path) => WebDomain + path

const showToast = (text) => Toasts.show(text, {
    duration: Toasts.durations.SHORT,
    position: Toasts.positions.CENTER,
    shadow: true,
    animation: true,
    hideOnPress: true,  
    delay: 0,
});
const showToastSuccess = (text = '成功！') => showToast(text);
const showToastError = (text = '失败！') => showToast(text);
const showToastLoad = (text = '加载中...') => Toast.loading(text, 60);
const hideToast = (key) => Portal.remove(key);
const alert = Modal.alert;
const operation = Modal.operation;
const prompt = Modal.prompt;
const showActionSheet = ActionSheet.showActionSheetWithOptions

const appVersion = '2.1'

var __data = {}
var loginUser = null
// "id": 3,
// "avatar": "",
// "user_nickname": "1234569",
// "mobile": "1234569",
// "sex": 0,
// "address": ""

var loginAddress = {
    city: '北京',
    lat: '',
    lng: '',
    cityId: '2',
    areaId: '3',
}

var cityData = []

//储存
function storage(key, value) {
    try {
        AsyncStorage.setItem(
            key,
            value,
            (error) => {
                console.log(error)
            }
        );
    } catch (error) {
        console.log(error)
    }
}
//读取
function readStorage(key) {
    try {
        AsyncStorage.getItem(
            key,
            (error, result) => {
                console.log(error)
                console.log(result)
                return result
            }
        );
    } catch (error) {
        console.log(error)
    }
}
async function storageObject(key, value) {
    try {
        const jsonValue = JSON.stringify(value)
        await AsyncStorage.setItem(key, jsonValue)
    } catch (error) {
        console.log(error)
    }
}
async function readStorageObject(key) {
    try {
        const jsonValue = await AsyncStorage.getItem(key)
        return jsonValue != null ? JSON.parse(jsonValue) : null
    } catch (error) {
        console.log(error)
    }
}

function findAddressCode(bd_areaCode) {

}


export default {
    __data,
    loginUser,
    loginAddress,
    baseURL,
    appVersion,
    cityData,
    getFullImage,
    showToast,
    prompt,
    operation,
    alert,
    showToastSuccess,
    showToastError,
    showToastLoad,
    hideToast,
    showActionSheet,


    storage,
    readStorage,
    storageObject,
    readStorageObject,


    findAddressCode,
}